package com.rcloud.server.sealtalk.manager;

import cn.hutool.core.date.DateField;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.rcloud.server.sealtalk.configuration.SealtalkConfig;
import com.rcloud.server.sealtalk.constant.ErrorCode;
import com.rcloud.server.sealtalk.controller.param.FaceAuthParam;
import com.rcloud.server.sealtalk.domain.*;
import com.rcloud.server.sealtalk.exception.ServiceException;
import com.rcloud.server.sealtalk.service.*;
import com.rcloud.server.sealtalk.sms.impl.YunPianSmsService;
import com.rcloud.server.sealtalk.util.BASE64DecodedMultipartFile;
import com.rcloud.server.sealtalk.util.MultipartFileToFile;
import com.rcloud.server.sealtalk.util.TencentMarketClient;
import com.rcloud.server.sealtalk.util.baidu.PersonVerify;
import com.rcloud.server.sealtalk.util.market.AliMarkApiClient;
import com.rcloud.server.sealtalk.xiangyun.NetOCRCommonClient;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import tk.mybatis.mapper.entity.Example;

import javax.annotation.Resource;
import java.io.File;
import java.io.IOException;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

/**
 * @author: zc
 * @date: 2021/06/16
 * @description: OCR处理类
 * @copyright (c) 20201, rongcloud.cn All Rights Reserved
 */
@Slf4j
@Service
public class FaceAuthManager extends BaseManager {

    @Resource
    private PersonVerify personVerify;

    @Resource
    private UserDocListService docListService;

    @Resource
    private CompanyInfoService companyInfoService;

    @Resource
    private UsersService usersService;

    @Resource
    private NetOCRCommonClient ocrCommonClient;

    @Resource
    private AliMarkApiClient aliMarkApiClient;

    @Resource
    private TencentMarketClient tencentMarketClient;

    @Resource
    private TobaccoLicenseInfoService tobaccoLicenseInfoService;

    @Resource
    private FoodLicenseInfoService foodLicenseInfoService;

    @Resource
    private SealtalkConfig config;

    @Resource
    private YunPianSmsService yunPianSmsService;

    @Autowired
    private AttachFileService attachFileService;

    /**
     * 用户人脸认证处理
     */
    public Boolean faceAuthHandle(FaceAuthParam param, Integer userId, Integer postType) throws ServiceException {
        log.info("用户人脸认证处理.param:[{}]", param.toString());
        Users user = usersService.getByPrimaryKey(userId);
        if (user == null) {
            throw new ServiceException(ErrorCode.USER_NOT_EXIST);
        }
        if (user.getIsReal() == null || user.getIsReal() == 0) {
            throw new ServiceException(ErrorCode.USER_NOT_AUTH_ERROR);
        }

        if (user.getPayAuthStatus() == 0) {
            throw new ServiceException(ErrorCode.USER_NOT_PAY_ERROR);
        }
        BigDecimal score = BigDecimal.ZERO;
        //如果请求成功
        if (postType == 1) {
            String result = tencentMarketClient.faceAuthVerify(param.getImageStr(), user.getName(), user.getIdentitycard());
            JSONObject jsonObject = JSONObject.parseObject(result);
            if ("Success".equals(jsonObject.getString("Result"))) {
                score = jsonObject.getBigDecimal("Sim");
            } else {
                throw new ServiceException(ErrorCode.FACE_REQ_FAIL_ERROR);
            }
        } else {
            String result = personVerify.personVerify(param.getImageStr(), user.getName(), user.getIdentitycard()
                    , sealtalkConfig.getClientId(), sealtalkConfig.getClientSecret());
            JSONObject jsonObject = JSONObject.parseObject(result);
            if (jsonObject.getIntValue("error_code") == 0 && "SUCCESS".equals(jsonObject.getString("error_msg"))) {
                JSONObject result1 = jsonObject.getJSONObject("result");
                score = result1.getBigDecimal("score");
            } else {
                throw new ServiceException(ErrorCode.FACE_REQ_FAIL_ERROR);
            }
        }
        //代表人脸身份认证失败
        if (score.compareTo(new BigDecimal("80")) < 0) {
            throw new ServiceException(ErrorCode.FACE_AUTH_FAIL_ERROR);
        }
        //需要做的就是修改用户刷脸识别的标识
        Users paramsUser = new Users();
        paramsUser.setId(userId);
        paramsUser.setIsFace(1);
        try {
            //图片处理
            MultipartFile file = BASE64DecodedMultipartFile.base64ToMultipart(param.getImageStr());
            if (file != null) {
                String fileName = attachFileService.uploadFile(file.getBytes(), file.getOriginalFilename());
                String s = "https://" + sealtalkConfig.getQiniuBucketDomain() + "/" + fileName;
                //增加人脸识别的图片
                paramsUser.setFaceAuthImg(s);
            }
        } catch (Exception e) {
            log.error("人脸识别验证图片处理错误");
        }
        usersService.updateByPrimaryKeySelective(paramsUser);
        //进入证件审核的接口
        try {
            authCert(userId);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return true;
    }

    public String authCert(Integer userId) throws IOException, ServiceException {
        StringBuilder resultInfo = new StringBuilder();
        log.info("进入证件审核的方法---------------------进入");
        //todo 成功的状态下 处理企业资质的 相关的识别和认证
        Example example = new Example(UserDocList.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("userId", userId);
        criteria.andEqualTo("authStatus", 0);
        List<UserDocList> userDocLists = docListService.getByExample(example);
        //识别加查询
        for (UserDocList doc : userDocLists) {
            //营业执照识别
            if (doc.getDataType() == 3) {
                resultInfo.append("营业执照审核结果:");
                resultInfo.append(businessLicense(doc));
            }
            //烟草证识别和查询  阿里云市场的接口
//            if (doc.getDataType() == 4) {
//                resultInfo.append("烟草证审核结果:");
//                resultInfo.append(tobaccoLicense(doc));
//            }
            //食品许可证识别
//            if (doc.getDataType() == 5) {
//                footLicense(doc);
//            }
        }
        String s = updateSuccessInfo(userId);
        resultInfo.append("最终审核结果信息: ").append(s);
        log.info("退出证件审核的方法---------------------退出");
        return resultInfo.toString();
    }

    /**
     * 用户审核资料信息后的修改
     */
    private String updateSuccessInfo(Integer userId) throws ServiceException {
        Users user = usersService.getByPrimaryKey(userId);
        //在用户全部都认证过的情况下 进行商户的判定
        if (user.getIsReal() == 1 && user.getIsFace() == 1 && user.getPayAuthStatus() == 1) {
            //查询营业执照
            UserDocList business = docListService.getOne(UserDocList.builder()
                    .userId(userId).dataType(3).build());
            //查询烟草证信息
//            UserDocList tobacco = docListService.getOne(UserDocList.builder()
//                    .userId(userId).dataType(4).build());
            //这个条件同时成立的情况下才能认证成功   && (tobacco != null && tobacco.getAuthStatus() == 1)
            if (business != null && business.getAuthStatus() == 1) {
                //修改用户的商户认证状态
                Users paramUser = new Users();
                paramUser.setId(userId);
                paramUser.setIsMerchant(1);
                //设置认证有效期，时间为 一年
                DateTime offset = DateUtil.offset(new Date(), DateField.YEAR, 1);
                paramUser.setAuthValidDate(offset);
                usersService.updateByPrimaryKeySelective(paramUser);
                //发送审核成功的短信
                yunPianSmsService.sendSmsAuthInfo(user.getPhone(), config.getRongcloudSmsAuthSuccessTemplateId());
                return "商户身份认证审核成功!";
            } else {
//                if ((business != null && business.getAuthStatus() == 1) && (tobacco != null && tobacco.getAuthStatus() == 0)) {
//                    //发送营业执照审核通过的短信
//                    return "资料信息已提交正在审核中！";
//                }else {
//                    //发送审核失败的短信
//                    yunPianSmsService.sendSmsAuthInfo(user.getPhone(),config.getRongcloudSmsAuthFailTemplateId());
//                    return "资料信息尚未全部通过";
//                }

                //发送审核失败的短信
                yunPianSmsService.sendSmsAuthInfo(user.getPhone(), config.getRongcloudSmsAuthFailTemplateId());
                return "资料信息审核未通过！";
            }
        } else {
            return "用户实名认证还未通过";
        }
    }


    /**
     * 营业执照的识别
     */
    private String businessLicense(UserDocList doc) throws IOException {
        String fileUrl = "https://" + config.getQiniuBucketDomain() + "/" + doc.getPostUrl();
        File file = MultipartFileToFile.getFileByUrl(fileUrl);
        //先进行识别  再进行查询
        String licenseStr = ocrCommonClient.identifyBusinessLicense(file);
        JSONObject license = JSONObject.parseObject(licenseStr);
        JSONObject message = license.getJSONObject("message");
        //查询成功
        if ("0".equals(message.getString("status"))) {
            JSONObject cardsinfo = license.getJSONArray("cardsinfo").getJSONObject(0);
            CompanyInfo paramsCom = CompanyInfo.builder().build();
            //查询企业识别的信息
            JSONArray items = cardsinfo.getJSONArray("items");
            for (int i = 0; i < items.size(); i++) {
                JSONObject json = items.getJSONObject(i);
                if ("统一社会信用代码".equals(json.getString("desc"))) {
                    paramsCom.setUnifySocialCode(json.getString("content"));
                }
                if ("组织机构代码".equals(json.getString("desc"))) {
                    paramsCom.setOrgCode(json.getString("content"));
                }
                if ("税务登记证号".equals(json.getString("desc"))) {
                    paramsCom.setTexNum(json.getString("content"));
                }
                if ("社保登记号".equals(json.getString("desc"))) {
                    paramsCom.setSocialSecurityNum(json.getString("content"));
                }
                if ("统计证证号".equals(json.getString("desc"))) {
                    paramsCom.setStatisticalNum(json.getString("content"));
                }
                if ("名称".equals(json.getString("desc"))) {
                    paramsCom.setCompanyName(json.getString("content"));
                }
                if ("类型".equals(json.getString("desc"))) {
                    paramsCom.setCompanyMold(json.getString("content"));
                }
                if ("住所".equals(json.getString("desc"))) {
                    paramsCom.setCompanyAddr(json.getString("content"));
                }
                if ("经营者".equals(json.getString("desc")) || "法定代表人".equals(json.getString("desc"))) {
                    paramsCom.setLegalPerson(json.getString("content"));
                }
                if ("组成形式".equals(json.getString("desc"))) {
                    paramsCom.setComposingForm(json.getString("content"));
                }
                if ("注册资本".equals(json.getString("desc"))) {
                    paramsCom.setRegisteredCapital(json.getString("content"));
                }
                if ("成立日期".equals(json.getString("desc"))) {
                    paramsCom.setEstablishDate(json.getString("content"));
                }
                if ("营业期限".equals(json.getString("desc"))) {
                    paramsCom.setOperatingPeriod(json.getString("content"));
                }
                if ("经营范围".equals(json.getString("desc"))) {
                    paramsCom.setBusinessScope(json.getString("content"));
                }
                if ("登记机关".equals(json.getString("desc"))) {
                    paramsCom.setRegistrationAuthority(json.getString("content"));
                }
                if ("登记日期".equals(json.getString("desc"))) {
                    paramsCom.setRegistrationDate(json.getString("content"));
                }
            }
            //进行企业查询
            String companyStr = ocrCommonClient.queryBusinessInfo(paramsCom.getUnifySocialCode());
            JSONObject company = JSONObject.parseObject(companyStr);
            JSONObject queryMessage = company.getJSONObject("message");
            //代表查询成功
            if (queryMessage.getIntValue("status") == 2) {
                boolean social = false;//社会统一编码标识
                boolean frdb = false; // 法人代表标识
                boolean realSame = false; // 实名信息和法人的是否一直的代表标识
                JSONObject queryCardsinfo = company.getJSONObject("cardsinfo");
                JSONArray veritemArray = queryCardsinfo.getJSONArray("veritem");
                for (int i = 0; i < veritemArray.size(); i++) {
                    JSONObject veritem = veritemArray.getJSONObject(i);
                    //判断企业识别出的法人名称和查询出的法人名称是不是一致 一致通过
                    if ("统一社会信用代码".equals(veritem.getString("desc"))) {
                        //判断统一社会信用编码是否一致
                        if (paramsCom.getUnifySocialCode().equals(veritem.getString("content"))) {
                            social = true;
                        }
                    }
                    if ("企业法定代表人".equals(veritem.getString("desc"))) {
                        //判断法定代表人是否一致
                        if (paramsCom.getLegalPerson().equals(veritem.getString("content"))) {
                            frdb = true;
                        }
                        Users users = usersService.getByPrimaryKey(doc.getUserId());
                        if (users.getName().equals(veritem.getString("content"))) {
                            realSame = true;
                        }
                    }
                    if ("经营状态".equals(veritem.getString("desc"))) {
                        paramsCom.setEntstatus(veritem.getString("content"));
                    }
                    if ("所属工商局".equals(veritem.getString("desc"))) {
                        paramsCom.setRegistrationAuthority(veritem.getString("content"));
                    }

                    if ("组织机构号".equals(veritem.getString("desc"))) {
                        paramsCom.setOrgCode(veritem.getString("content"));
                    }
                }
                //判断同时都对的情况下
                if (social && frdb && realSame) {
                    doc.setAuthStatus(1);
                    doc.setAuthTime(new Date());
                    docListService.updateByPrimaryKeySelective(doc);
                    //添加企业基础信息
                    paramsCom.setUserId(doc.getUserId());
                    CompanyInfo one = companyInfoService.getOne(CompanyInfo.builder().userId(doc.getUserId()).build());
                    if (one != null) {
                        companyInfoService.updateByPrimaryKeySelective(paramsCom);
                    } else {
                        companyInfoService.saveSelective(paramsCom);
                    }
                    return "营业执照识别查询比对成功";
                } else {
                    //更新认证失败的标识
                    doc.setAuthStatus(2);
                    doc.setAuthTime(new Date());
                    docListService.updateByPrimaryKeySelective(doc);
                    return "营业执照识别查询比对失败";
                }
            } else {
                //更新认证失败的标识
                doc.setAuthStatus(2);
                doc.setAuthTime(new Date());
                docListService.updateByPrimaryKeySelective(doc);
                return queryMessage.getString("value");
            }
        } else {
            //更新认证失败的标识
            doc.setAuthStatus(2);
            doc.setAuthTime(new Date());
            docListService.updateByPrimaryKeySelective(doc);
            return message.getString("value");
        }
    }

    /**
     * 烟草证识别和查询
     */
    private String tobaccoLicense(UserDocList doc) {
        String fileUrl = "https://" + config.getQiniuBucketDomain() + "/" + doc.getPostUrl();
        //先进行识别  再进行查询
        String licenseStr = aliMarkApiClient.recognizeCigaretteCert(fileUrl);
        if (licenseStr != null) {
            JSONObject licenseBody = JSONObject.parseObject(licenseStr);
            //查询成功
            if ("艾科瑞特，让企业业绩长青".equals(licenseBody.getString("烟草专卖零售许可证识别状态"))) {
                JSONObject license = licenseBody.getJSONObject("烟草专卖零售许可证实体信息");
                TobaccoLicenseInfo paramsTo = new TobaccoLicenseInfo();
                //查询企业识别的信息
                paramsTo.setLicenseKey(license.getString("许可证号"));
                paramsTo.setCompanyName(license.getString("企业（字号）名称"));
                paramsTo.setPrincipalName(license.getString("负责人（经营者）姓名"));
                paramsTo.setBusinessType(license.getString("企业类型（组织形式）"));
                paramsTo.setOperationSite(license.getString("经营场所"));
                paramsTo.setToleranceRange(license.getString("许可范围"));
                paramsTo.setSupplier(license.getString("供货单位"));
                paramsTo.setExpiryDateFrom(license.getString("有效期限自"));
                paramsTo.setExpiryDateTo(license.getString("有效期限至"));
                //进行烟草证查询
                String queryCert = aliMarkApiClient.queryTobacooCert(paramsTo.getLicenseKey());
                if (queryCert != null) {
                    JSONObject tobacco = JSONObject.parseObject(queryCert);
                    if ("艾科瑞特，让企业业绩长青".equals(tobacco.getString("烟草专卖零售许可证数据状态"))) {
                        Users users = usersService.getByPrimaryKey(doc.getUserId());
                        //判断企业名称和经营者是同一个人的话那么这个证件则是有效的
                        if (paramsTo.getCompanyName().equals(tobacco.getString("企业名称"))
                                && paramsTo.getPrincipalName().equals(tobacco.getString("经营者"))
                                && users.getName().equals(tobacco.getString("经营者"))) {
                            //todo 还需要判断有效期 ，有效期内就是有效的
                            doc.setAuthStatus(1);
                            doc.setAuthTime(new Date());
                            docListService.updateByPrimaryKeySelective(doc);
                            //成功之后进行记录烟草经营许可证信息
                            paramsTo.setCreateTime(new Date());
                            paramsTo.setUserId(doc.getUserId());
                            TobaccoLicenseInfo one = tobaccoLicenseInfoService.getOne(TobaccoLicenseInfo.builder().userId(doc.getUserId()).build());
                            if (one != null) {
                                tobaccoLicenseInfoService.updateByPrimaryKeySelective(paramsTo);
                            } else {
                                tobaccoLicenseInfoService.saveSelective(paramsTo);
                            }
                        } else {
                            //更新认证失败的标识
                            doc.setAuthStatus(2);
                            doc.setAuthTime(new Date());
                            docListService.updateByPrimaryKeySelective(doc);
                        }
                    } else {
                        //更新认证失败的标识
                        doc.setAuthStatus(2);
                        doc.setAuthTime(new Date());
                        docListService.updateByPrimaryKeySelective(doc);
                    }
                } else {
                    //更新认证失败的标识
                    doc.setAuthStatus(2);
                    doc.setAuthTime(new Date());
                    docListService.updateByPrimaryKeySelective(doc);
                }
            } else {
                //更新认证失败的标识
                doc.setAuthStatus(2);
                doc.setAuthTime(new Date());
                docListService.updateByPrimaryKeySelective(doc);
            }
            return licenseBody.getString("烟草专卖零售许可证识别状态");
        } else {
            //更新认证失败的标识
            doc.setAuthStatus(2);
            doc.setAuthTime(new Date());
            docListService.updateByPrimaryKeySelective(doc);
            return "烟草零售专卖许可证识别失败";
        }

    }

    /**
     * 食品许可证
     */
    private void footLicense(UserDocList doc) {
        String fileUrl = "https://" + config.getQiniuBucketDomain() + "/" + doc.getPostUrl();
        //先进行识别  再进行查询
        String licenseStr = aliMarkApiClient.foodLicenseIdentification(fileUrl);
        if (licenseStr != null) {
            JSONObject licenseBody = JSONObject.parseObject(licenseStr);
            //查询成功
            if ("艾科瑞特，让企业业绩长青".equals(licenseBody.getString("食品经营许可证识别状态"))) {
                JSONObject license = licenseBody.getJSONObject("食品经营许可证实体信息");
                FoodLicenseInfo paramsFo = new FoodLicenseInfo();
                //查询食品许可证的识别
                paramsFo.setOperatorName(license.getString("经营者名称"));
                paramsFo.setCardNum(license.getString("社会信用代码（身份证号码）"));
                paramsFo.setLegalPerson(license.getString("法定代表人（负责人）"));
                paramsFo.setHomeAddr(license.getString("住所"));
                paramsFo.setOperationSite(license.getString("经营场所"));
                paramsFo.setMainBodyForms(license.getString("主体业态"));
                paramsFo.setLicenseKey(license.getString("许可证编号"));
                paramsFo.setSuperviseOrg(license.getString("日常监督管理机构"));
                paramsFo.setSupervisePerson(license.getString("日常监督管理人员"));
                paramsFo.setLicenceIssuingAuthority(license.getString("发证机关"));
                paramsFo.setSigner(license.getString("签发人"));
                paramsFo.setExpiryDateTo(license.getString("有效期限至"));
                paramsFo.setCreateTime(new Date());
                Users users = usersService.getByPrimaryKey(doc.getUserId());
                //实名认证信息和法人信息一致就通过
                if (users.getName().equals(paramsFo.getLegalPerson())) {
                    //todo 还需要判断有效期 ，有效期内就是有效的
                    doc.setAuthStatus(1);
                    doc.setAuthTime(new Date());
                    docListService.updateByPrimaryKeySelective(doc);
                    paramsFo.setUserId(doc.getUserId());
                    //识别成功保存信息
                    FoodLicenseInfo one = foodLicenseInfoService.getOne(FoodLicenseInfo.builder().userId(doc.getUserId()).build());
                    if (one != null) {
                        foodLicenseInfoService.updateByPrimaryKeySelective(paramsFo);
                    } else {
                        foodLicenseInfoService.saveSelective(paramsFo);
                    }
                } else {
                    //更新认证失败的标识
                    doc.setAuthStatus(2);
                    doc.setAuthTime(new Date());
                    docListService.updateByPrimaryKeySelective(doc);
                }
            } else {
                //更新认证失败的标识
                doc.setAuthStatus(2);
                doc.setAuthTime(new Date());
                docListService.updateByPrimaryKeySelective(doc);
            }
        } else {
            //更新认证失败的标识
            doc.setAuthStatus(2);
            doc.setAuthTime(new Date());
            docListService.updateByPrimaryKeySelective(doc);
        }
    }

    /**
     * 烟草证识别和查询
     */
    public String queryTobaccoLicense(String licenseNum, Integer userId) throws ServiceException {
        Example example = new Example(UserDocList.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("userId", userId);
        criteria.andEqualTo("dataType", 4);
        UserDocList doc = docListService.getOneByExample(example);
        if (doc != null) {
            //进行烟草证查询
            String queryCert = aliMarkApiClient.queryTobacooCert(licenseNum);
            if (queryCert != null) {
                JSONObject tobacco = JSONObject.parseObject(queryCert);
                if ("艾科瑞特，让企业业绩长青".equals(tobacco.getString("中国烟草专卖零售许可证数据状态"))) {
                    Users users = usersService.getByPrimaryKey(userId);
                    //判断企业名称和经营者是同一个人的话那么这个证件则是有效的
                    JSONObject jsonObject = tobacco.getJSONObject("中国烟草专卖零售许可证数据实体信息");
                    if (users.getName().equals(jsonObject.getString("经营者"))) {
                        TobaccoLicenseInfo paramsTo = new TobaccoLicenseInfo();
                        //查询企业识别的信息
                        paramsTo.setLicenseKey(licenseNum);
                        paramsTo.setCompanyName(jsonObject.getString("企业名称"));
                        paramsTo.setPrincipalName(jsonObject.getString("经营者"));
                        paramsTo.setOperationSite(jsonObject.getString("经营场所"));
                        paramsTo.setToleranceRange(jsonObject.getString("许可范围"));
                        paramsTo.setExpiryDateFrom(jsonObject.getString("许可证有效期开始时间"));
                        paramsTo.setExpiryDateTo(jsonObject.getString("许可证有效期结束时间"));
                        paramsTo.setUserId(userId);
                        //成功之后进行记录烟草经营许可证信息
                        paramsTo.setCreateTime(new Date());
                        //todo 还需要判断有效期 ，有效期内就是有效的
                        doc.setAuthStatus(1);
                        doc.setAuthTime(new Date());
                        docListService.updateByPrimaryKeySelective(doc);
                        TobaccoLicenseInfo one = tobaccoLicenseInfoService.getOne(TobaccoLicenseInfo.builder().userId(doc.getUserId()).build());
                        if (one != null) {
                            tobaccoLicenseInfoService.updateByPrimaryKeySelective(paramsTo);
                        } else {
                            tobaccoLicenseInfoService.saveSelective(paramsTo);
                        }
                        //用户审核信息判定
                        return updateSuccessInfo(userId);
                    } else {
                        //更新认证失败的标识
                        doc.setAuthStatus(2);
                        doc.setAuthTime(new Date());
                        docListService.updateByPrimaryKeySelective(doc);
                        return "企业名称和经营者不是同一个人！";
                    }
                } else {
                    //更新认证失败的标识
                    doc.setAuthStatus(2);
                    doc.setAuthTime(new Date());
                    docListService.updateByPrimaryKeySelective(doc);
                    return tobacco.getString("烟草专卖零售许可证数据状态");
                }
            } else {
                //更新认证失败的标识
                doc.setAuthStatus(2);
                doc.setAuthTime(new Date());
                docListService.updateByPrimaryKeySelective(doc);
                return "未查询到烟草证信息！";
            }
        } else {
            throw new ServiceException(ErrorCode.TOBACCO_DOC_NOT_UPLOAD_ERROR);
        }
    }

}